package com.lanlian.cayman.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.bean.CMinute;
import com.example.bean.FenshiDataResponse;
import com.example.bean.MyStatic;
import com.example.bean.StickData;
import com.example.myview.CrossView;
import com.example.myview.FenshiView;
import com.example.myview.ImageViewPlus;
import com.example.myview.KLineView;
import com.example.myview.MsgView;
import com.example.utils.ColorUtil2;
import com.example.utils.CountUtil;
import com.example.utils.NumberUtil2;
import com.lanlian.cayman.R;
import com.lanlian.cayman.bean.GearBean;
import com.lanlian.cayman.bean.MinXiBean;
import com.lanlian.cayman.bean.MyContractBean;
import com.lanlian.cayman.dialog.DrawLinePopup;
import com.lanlian.cayman.utils.MResUtil;
import com.lanlian.cayman.utils.NumberManager;
import com.lanlian.commonlib.dao.DBManager;
import com.lanlian.utillib.DisplayUtil;
import com.scwang.smartrefresh.layout.util.DensityUtil;

import java.util.ArrayList;

/**
 * <pre>
 *
 *      1374405188@qq.com
 *     date   : 2018/8/16 10:17
 *     desc   : 分时图 及k线
 *     version: 1.0
 * </pre>
 */
public class KlineView extends LinearLayout implements View.OnClickListener ,View.OnTouchListener{

    private FenshiView fenshiView;
    private CrossView crossView;
    private CrossView crossView_fs;
    //滑动十字线时，显示对应点详情的地方
    private MsgView msgText;
    private ImageViewPlus iv_fangdajin;
    private MsgView msgText_fenshi;
    //分时数据
    private FenshiDataResponse data;
    //滑动十字线时，显示对应点详情的地方
    private ArrayList<StickData> list;
    public KLineView kLineView;

    private RelativeLayout rl_kl;
    private RelativeLayout rl_fs;



    Activity context;
    private int scale_price=2;
    /**
     * 昨天收盘价格
     */
    private String last_price="";
    LinearLayout ll_zhibiao;
    LinearLayout ll_pankou;
    LinearLayout ll_wudang;
    LinearLayout ll_minxi;
    LinearLayout ll_img;
    private GearView gv;
    private MinXiView mx;
    private TextView gv_text;
    private TextView mx_text;
    ImageView iv_jiantou;

    LinearLayout ll_ma;
    TextView tv_ma5;
    TextView tv_ma10;
    TextView tv_ma20;
    TextView tv_ma30;

    LinearLayout ll_ema;
    TextView tv_ema5;
    TextView tv_ema10;
    TextView tv_ema20;
    TextView tv_ema30;

    LinearLayout ll_boll;

    TextView tv_md;
    TextView tv_up;
    TextView tv_dn;
    /**
     * 当前指标索引 1 ma 2ema 3boll
     */
    int cIndex=1;



    MyContractBean mb;
    LinearLayout ll_curent;
    TextView tv_price2;
    TextView tv_change2;
    TextView tv_chg2;
    TextView tv_junjia;

    StickData csd;
    OnClickListener ocl;

    /**
     * 滑动时候x坐标
     */
    float x;
    /**
     * 滑动时候y坐标
     */
    float y;
    /**
     * 左滑收拾
     */
    DrawLinePopup dld;
    /**
     * 画图工具view
     */
    StyleUtil ll_style;
    protected GestureDetector gestureDetector;
    public KlineView(Context context) {
        super(context);
        this.context=(Activity) context;
        initView();

    }

    public KlineView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context=(Activity) context;
        initView();
    }



    private int type=0;
    /**
     * 显示类型 0分时图，1 1分钟 5 5分钟 ......
     * @param type
     */
   public void setType(int type,int zhibiao)
   {

       this.type=type;
       if( msgText!=null)
       {
           msgText.setVisibility(View.GONE);
       }

       if(type==0)
       {
           crossView.setVisibility(View.GONE);
           crossView_fs.setVisibility(View.GONE);
           rl_fs.setVisibility(View.VISIBLE);
           rl_kl.setVisibility(View.GONE);
          // data = new Gson().fromJson(common.sb.toString(), FenshiDataResponse.class);
          // fenshiView.setDataAndInvalidate(data);
           ll_ma.setVisibility(GONE);
           ll_ema.setVisibility(GONE);
           ll_boll.setVisibility(GONE);
           ll_curent.setVisibility(VISIBLE);

       }
       else
       {
           crossView.setVisibility(View.GONE);
           crossView_fs.setVisibility(View.GONE);
           ll_curent.setVisibility(GONE);
           ll_ma.setVisibility(GONE);
           ll_ema.setVisibility(GONE);
           ll_boll.setVisibility(GONE);
           if(zhibiao==0)
           {
               ll_ma.setVisibility(VISIBLE);
           }
           else if(zhibiao==1)
           {
               ll_ema.setVisibility(VISIBLE);
           }
           else if(zhibiao==2)
           {
               ll_boll.setVisibility(VISIBLE);
           }



           rl_fs.setVisibility(View.GONE);
           rl_kl.setVisibility(View.VISIBLE);
           if(list!=null) {
               kLineView.setUsedViews(crossView, msgText);
               kLineView.setType(type);
               kLineView.setDataAndInvalidate(list);
           }

       }
   }

    protected void initView() {
        //ColorUtil.setUpColor(MResUtil.getColorType());
        ColorUtil2.setType(MResUtil.getColorType());
        ColorUtil2.setZhuTi(DBManager.getInstance().getTopicColor());
        LayoutInflater inflater=context.getLayoutInflater();
        View view = inflater.inflate(R.layout.view_kline, null);
        iv_fangdajin=view.findViewById(R.id.iv_fangdajin);
        tv_junjia=view.findViewById(R.id.tv_junjia);
        ll_pankou=view.findViewById(R.id.ll_pankou);
        ll_wudang=view.findViewById(R.id.ll_wudang);
        ll_wudang.setOnClickListener(this);
        ll_img=view.findViewById(R.id.ll_img);
        ll_img.setOnClickListener(this);
        iv_jiantou=view.findViewById(R.id.iv_jiantou);

        ll_minxi=view.findViewById(R.id.ll_minxi);
        ll_minxi.setOnClickListener(this);
        ll_zhibiao=view.findViewById(R.id.ll_zhibiao);

        gv_text=view.findViewById(R.id.gv_text);
        mx_text=view.findViewById(R.id.mx_text);
        gv=view.findViewById(R.id.gv);
        mx=view.findViewById(R.id.mx);



        ll_curent=view.findViewById(R.id.ll_curent);
        tv_price2=view.findViewById(R.id.tv_price2);
        tv_change2=view.findViewById(R.id.tv_change2);
        tv_chg2=view.findViewById(R.id.tv_chg2);


        ll_ma=view.findViewById(R.id.ll_ma);
        tv_ma5=view.findViewById(R.id.tv_ma5);
        tv_ma10=view.findViewById(R.id.tv_ma10);
        tv_ma20=view.findViewById(R.id.tv_ma20);
        tv_ma30=view.findViewById(R.id.tv_ma30);

        ll_ema=view.findViewById(R.id.ll_ema);
        tv_ema5=view.findViewById(R.id.tv_ema5);
        tv_ema10=view.findViewById(R.id.tv_ema10);
        tv_ema20=view.findViewById(R.id.tv_ema20);
        tv_ema30=view.findViewById(R.id.tv_ema30);

        ll_boll=view.findViewById(R.id.ll_boll);
        tv_md=view.findViewById(R.id.tv_md);
        tv_up=view.findViewById(R.id.tv_up);
        tv_dn=view.findViewById(R.id.tv_dn);
        ll_style=view.findViewById(R.id.ll_style);



        fenshiView = (FenshiView)view.findViewById(R.id.cff_fenshiview);



        crossView = (CrossView) view.findViewById(R.id.cff_cross);
        crossView_fs = (CrossView) view.findViewById(R.id.fs_cross);
        //msgText=view.findViewById(R.id.msgText);
        rl_fs=view.findViewById(R.id.rl_fs);
        rl_kl=view.findViewById(R.id.rl_kl);


        kLineView=view.findViewById(R.id.cff_klineview);



        kLineView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                kLineView.heightToParent=event.getY();
                return false;
            }
        });

        if(type==0)
        {
            rl_fs.setVisibility(View.VISIBLE);
            rl_kl.setVisibility(View.GONE);
            //data = new Gson().fromJson(common.sb.toString(), FenshiDataResponse.class);
            fenshiView.setUsedViews(crossView_fs, msgText);
            if(data!=null) {
                //fenshiView.setDataAndInvalidate(data);
            }
            ll_ma.setVisibility(GONE);
            ll_ema.setVisibility(GONE);
            ll_boll.setVisibility(GONE);
            ll_curent.setVisibility(VISIBLE);
        }
        else
        {
           // list = (ArrayList<StickData>)new Gson().fromJson(common.sb_kline.toString(), MyList.class).data;
            ll_curent.setVisibility(GONE);
            ll_ma.setVisibility(VISIBLE);
            ll_ema.setVisibility(GONE);
            ll_boll.setVisibility(GONE);
            rl_fs.setVisibility(View.GONE);
            rl_kl.setVisibility(View.VISIBLE);
            kLineView.setUsedViews(crossView, msgText);
            kLineView.setType(1);
            //kLineView.setDataAndInvalidate(list);

        }
        addView(view);


        setShouShi();

    }

    public void setTop(MyContractBean mb)
    {
           this.mb=mb;
           if(crossView_fs.getVisibility()!=View.VISIBLE)
           {
               setTop(mb,null);
           }

    }
    private void setTop(MyContractBean mb, String name)
    {

        TextView tv_price=tv_price2;
        TextView tv_change=tv_change2;
        TextView tv_chg=tv_chg2;
        if(mb!=null) {
            tv_price.setText(mb.last);
            tv_change.setText(mb.change);
            tv_chg.setText(mb.chg);


            tv_junjia.setText(NumberUtil2.getString(mb.Average+"","1",scale_price));
            if(NumberManager.isDaYu(mb.change,"0")>0)
            {
                tv_price.setTextColor(MResUtil.getUpColor());
                tv_change.setTextColor(MResUtil.getUpColor());
                tv_chg.setTextColor(MResUtil.getUpColor());

                if(mb.change.contains("+"))
                {
                    tv_change.setText(mb.change);
                }
                else
                {
                    tv_change.setText("+"+mb.change);
                }
                if(mb.chg.contains("+"))
                {
                    tv_chg.setText(mb.chg);
                }
                else
                {
                    tv_chg.setText("+"+mb.chg);
                }
            }
            else if(NumberManager.isDaYu(mb.change,"0")==0)
            {
                tv_price.setTextColor(MResUtil.getPingColor());
                tv_change.setTextColor(MResUtil.getPingColor());
                tv_chg.setTextColor(MResUtil.getPingColor());
            }
            else
            {
                tv_price.setTextColor(MResUtil.getDownColor());
                tv_change.setTextColor(MResUtil.getDownColor());
                tv_chg.setTextColor(MResUtil.getDownColor());

                if(mb.change.contains("-"))
                {
                    tv_change.setText(mb.change);
                }
                else
                {
                    tv_change.setText("-"+mb.change);
                }
                if(mb.chg.contains("-"))
                {
                    tv_chg.setText(mb.chg);
                }
                else
                {
                    tv_chg.setText("-"+mb.chg);
                }
            }
        }
    }
    public void setOnClick(OnClickListener ocl)
    {
        this.ocl=ocl;
        fenshiView.setSingOn(ocl);
        kLineView.setSingOn(ocl);
    }
    public void setMsgLL(MsgView msgText)
    {
        this.msgText=msgText;
        fenshiView.setUsedViews(crossView_fs, msgText);

    }
    public void setScalePrice(int scale_price)
    {
        this.scale_price=scale_price;
        kLineView.setScalePrice(scale_price);
        fenshiView.setScalePrice(scale_price);

    }
    public void setLastPrice(String last_price)
    {
        this.last_price=last_price;
        mx.setLastDayPrice(last_price);

    }
   public void setData(ArrayList<StickData> list,int type)
   {
       this.list=list;
       kLineView.setType(type);
       //setType(type);
       if(list!=null) {
           kLineView.setUsedViews(crossView, msgText);

           kLineView.setDataAndInvalidate(list);
           if(list.size() >1) {
               csd=list.get(list.size() - 1);
               setMa(list.get(list.size() - 1));
           }
       }
       msgText.setIcb(new MsgView.IcbCall() {
           @Override
           public void call(Object obj,float x, float y) {
               if(obj!=null&&obj instanceof StickData)
               {
                   StickData sd=(StickData) obj;
                   TextView tv_time=msgText.findViewById(R.id.tv_time);
                   TextView tv_open=msgText.findViewById(R.id.tv_open);
                   TextView tv_close=msgText.findViewById(R.id.tv_close);
                   TextView tv_up=msgText.findViewById(R.id.tv_up);
                   TextView tv_down=msgText.findViewById(R.id.tv_down);
                   TextView tv_chg=msgText.findViewById(R.id.tv_chg_msg);
                   TextView tv_vol=msgText.findViewById(R.id.tv_vol);
                   tv_time.setText(sd.getTime2());


                  // TextView tv_test=msgText.findViewById(R.id.tv_test);
//                  if(tv_test!=null)
//                  {
//                      tv_test.setText(sd.test_time);
//                  }
                   if(type==24)
                   {
                       tv_time.setText(sd.getTime1());
                   }
                   tv_open.setText(NumberUtil2.getString(sd.getOpen()+"","1",scale_price));
                   tv_up.setText(NumberUtil2.getString(sd.getHigh()+"","1",scale_price));
                   tv_down.setText(NumberUtil2.getString(sd.getLow()+"","1",scale_price));
                   tv_vol.setText(NumberUtil2.getString(sd.getCount()+"","1",0));
                   tv_close.setText(NumberUtil2.getString(sd.getClose()+"","1",scale_price));
                   RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

                   int width=DisplayUtil.getScreenWidth(context);
                   width=getWidth();
                   if(x<width/2)
                   {
                       lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                       int m=DensityUtil.dp2px(16);
                       lp.setMargins(0,m,DisplayUtil.dip2px(context,50),0);
                   }
                   else
                   {
                       lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                       int m=DensityUtil.dp2px(16);
                       lp.setMargins(0,m,0,0);
                   }
                   msgText.setLayoutParams(lp);
                   if(cIndex==1)
                   {
                       setMa(sd);
                   }
                   else  if(cIndex==2)
                   {
                       seteMa(sd);
                   }
                   else if(cIndex==3)
                   {
                       setBoll(sd);
                   }

                   //处理涨跌颜色
                   int index= list.indexOf(sd);
                   if(index>0)
                   {
                       double last_close=list.get(index-1).getClose();
                       //处理涨跌幅
                       String s_chg= CountUtil.getChg(last_close+"",sd.getClose()+"",scale_price);
                       tv_chg.setText(s_chg+"%");

                       String s_last_close= NumberUtil2.getString(last_close+"","1",scale_price);
                       MResUtil.setColor(tv_open,NumberUtil2.isDaYu(tv_open.getText().toString(),s_last_close));
                       MResUtil.setColor(tv_close,NumberUtil2.isDaYu(tv_close.getText().toString(),s_last_close));
                       MResUtil.setColor(tv_up,NumberUtil2.isDaYu(tv_up.getText().toString(),s_last_close));
                       MResUtil.setColor(tv_chg,NumberUtil2.isDaYu(s_chg,"0"));
                       MResUtil.setColor(tv_down,NumberUtil2.isDaYu(tv_down.getText().toString(),s_last_close));
                   }
                   else
                   {
                       tv_chg.setText("0.00"+"%");
                       tv_chg.setTextColor(0xff5a5a5a);
                   }

               }
           }

           @Override
           public void cancle(Object obj) {
               if(obj!=null&&obj instanceof StickData) {
                   StickData sd = (StickData) obj;
                   if (cIndex == 1) {
                       setMa(sd);
                   } else if (cIndex == 2) {
                       seteMa(sd);
                   } else if (cIndex == 3) {
                       setBoll(sd);
                   }
               }

           }
       });




       kLineView.setMaBack(new MsgView.IcbCall() {
           @Override
           public void call(Object obj, float x, float y)
           {
               StickData sd=(StickData) obj;
               if(cIndex==1)
               {
                   setMa(sd);
               }
               else  if(cIndex==2)
               {
                   seteMa(sd);
               }
               else if(cIndex==3)
               {
                   setBoll(sd);
               }
           }

           @Override
           public void cancle(Object obj) {

           }
       });


   }
   public void setMa( StickData sd)
   {
       String sma5=sd.getSma5()+"";
       String sma10=sd.getSma10()+"";
       String sma20=sd.getSma20()+"";
       String sma30=sd.getSma30()+"";
       if(NumberUtil2.isDaYu(sd.getSma5()+"",StickData.defValue+"")==0)
      {
         tv_ma5.setText("--");
     }
     else
       {
           tv_ma5.setText(NumberManager.getString(sma5,"1",scale_price));
       }
       if(NumberUtil2.isDaYu(sd.getSma10()+"",StickData.defValue+"")==0)
       {
           tv_ma10.setText("--");
       }
       else
       {
           tv_ma10.setText(NumberManager.getString(sma10,"1",scale_price));
       }
       if(NumberUtil2.isDaYu(sd.getSma20()+"",StickData.defValue+"")==0)
       {
           tv_ma20.setText("--");
       }
       else
       {
           tv_ma20.setText(NumberManager.getString(sma20,"1",scale_price));
       }
       if(NumberUtil2.isDaYu(sd.getSma30()+"",StickData.defValue+"")==0)
       {
           tv_ma30.setText("--");
       }
       else
       {
           tv_ma30.setText(NumberManager.getString(sma30,"1",scale_price));
       }


   }
    public void seteMa( StickData sd)
    {

        String ema5=sd.getEma5()+"";
        String ema10=sd.getEma10()+"";
        String ema20=sd.getEma20()+"";
        String ema30=sd.getEma30()+"";
        if(NumberUtil2.isDaYu(sd.getEma5()+"",StickData.defValue+"")==0)
        {
            tv_ema5.setText("--");
        }
        else
        {
            tv_ema5.setText(NumberManager.getString(ema5,"1",scale_price));
        }

        if(NumberUtil2.isDaYu(sd.getEma10()+"",StickData.defValue+"")==0)
        {
            tv_ema10.setText("--");
        }
        else
        {
            tv_ema10.setText(NumberManager.getString(ema10,"1",scale_price));
        }

        if(NumberUtil2.isDaYu(sd.getEma20()+"",StickData.defValue+"")==0)
        {
            tv_ema20.setText("--");
        }
        else
        {
            tv_ema20.setText(NumberManager.getString(ema20,"1",scale_price));
        }
        if(NumberUtil2.isDaYu(sd.getEma30()+"",StickData.defValue+"")==0)
        {
            tv_ema30.setText("--");
        }
        else
        {
            tv_ema30.setText(NumberManager.getString(ema30,"1",scale_price));
        }


    }
    public void setBoll( StickData sd)
    {

        tv_md.setText(NumberManager.getString(sd.getMb()+"","1",scale_price));
        tv_up.setText(NumberManager.getString(sd.getUp()+"","1",scale_price));
        tv_dn.setText(NumberManager.getString(sd.getDn()+"","1",scale_price));
    }
   public void updateKlineData(StickData sd)
   {
       kLineView.upDateAndInvalidate(sd);
   }
   public void setMinXi(CMinute last)
   {
       MinXiBean mb=new MinXiBean();
       mb.time=StickData.getTime_hms(last.time);
       mb.price=NumberManager.getString(last.price+"","1",scale_price);
       mb.num=last.count+"";
       mx.setData(mb);
   }
   private void test(ArrayList<StickData> list)
   {
       StickData sd=null;
       for(int i=0;i<list.size();i++)
       {
           sd=list.get(i);
           sd.setCount(i*2);
           String s1="o:"+sd.getOpen()+"l:"+sd.getLast()+"vol:"+sd.getCount();
           Log.e("kline",s1);
       }
   }

   public void updateFenshiData(CMinute last)
   {
       setMinXi(last);
       fenshiView.updateDataAndInvalidate(last);

   }
   public void setFenshiData( FenshiDataResponse fd)
   {
       mx.reSet();
       //setType(0);

       //fenshiView.setUsedViews(crossView_fs, msgText);
       setWudangMinxi(MyStatic.is_yincang,MyStatic.wudang_minxi);
       fenshiView.setDataAndInvalidate(fd);

       msgText.setIcb(new MsgView.IcbCall() {
           @Override
           public void call(Object obj, float x, float y) {
               MyContractBean mb=new MyContractBean();
               if(obj instanceof  CMinute) {
                   CMinute cMinute = (CMinute) obj;
                   mb.last = NumberUtil2.getString(cMinute.getPrice() + "", "1", scale_price);
                   mb.change = NumberUtil2.getString(cMinute.getChange() + "", "1", scale_price);
                   mb.chg = cMinute.getChg();
                   mb.Average = cMinute.average;
                   setTop(mb, null);
               }
           }

           @Override
           public void cancle(Object obj) {
               setTop(mb,null);
           }
       });

   }
    public void setGearData(ArrayList<GearBean> buy, ArrayList<GearBean> sell)
    {
        gv.setLastDayPrice(last_price);
        gv.setData(buy,sell);
    }

    @Override
    public void onClick(View view) {
       switch (view.getId())
       {
           case R.id.ll_wudang:
                  MyStatic.wudang_minxi=0;
                   gv.setVisibility(VISIBLE);
                   mx.setVisibility(GONE);
                   gv.refresh();
                   gv_text.setTextColor(0xff4385F3);
                   mx_text.setTextColor(0xffADB9D3);

               break;
           case R.id.ll_minxi:
               MyStatic.wudang_minxi=1;
               gv.setVisibility(GONE);
               mx.setVisibility(VISIBLE);
               mx.refresh();
               gv_text.setTextColor(0xffADB9D3);
               mx_text.setTextColor(0xff4385F3);
               break;
           case R.id.ll_img:

               if(MyStatic.is_yincang==0)
               {
                   MyStatic.is_yincang=1;
                  setWudangMinxi(MyStatic.is_yincang,MyStatic.wudang_minxi);
               }
               else
               {
                   MyStatic.is_yincang=0;
                   setWudangMinxi(MyStatic.is_yincang,MyStatic.wudang_minxi);
               }
               break;

       }

    }
    public void setWudangMinxi(int is_yincang,int wudang_minxi)
    {
        if(is_yincang==0)
        {
            ll_pankou.setVisibility(VISIBLE);
            iv_jiantou.setImageResource(R.drawable.kline_icon_right);
            ll_wudang.setVisibility(VISIBLE);
            ll_minxi.setVisibility(VISIBLE);
        }
        else
        {
            ll_pankou.setVisibility(GONE);
            iv_jiantou.setImageResource(R.drawable.kline_icon_left2);
            ll_wudang.setVisibility(GONE);
            ll_minxi.setVisibility(GONE);
        }
        if(wudang_minxi==0)
        {
            gv.setVisibility(VISIBLE);
            mx.setVisibility(GONE);
            gv_text.setTextColor(0xff4385F3);
            mx_text.setTextColor(0xffADB9D3);
        }
        else
        {
            gv.setVisibility(GONE);
            mx.setVisibility(VISIBLE);
            gv_text.setTextColor(0xffADB9D3);
            mx_text.setTextColor(0xff4385F3);
        }
    }
    /**
     *  1 ma 2 ema 3boll
     * @param index
     */
    public void setTopZhiBiao(int index)
    {
        cIndex=index;
        if(cIndex==1)
        {
            if(csd!=null)
            {
                setMa(csd);
            }
            ll_boll.setVisibility(GONE);
            ll_ema.setVisibility(GONE);
            ll_ma.setVisibility(VISIBLE);
        }
        else if(cIndex==2)
        {
            if(csd!=null)
            {
                seteMa(csd);
            }
            ll_boll.setVisibility(GONE);
            ll_ema.setVisibility(VISIBLE);
            ll_ma.setVisibility(GONE);
        }
        else  if(cIndex==3)
        {
            if(csd!=null)
            {
                setBoll(csd);
            }
            ll_boll.setVisibility(VISIBLE);
            ll_ema.setVisibility(GONE);
            ll_ma.setVisibility(GONE);
        }
    }


    @Override
    public boolean onTouch(View v, MotionEvent event)
    {
       return false;
    }

    /**
     *
     * 设置左滑收拾
     */
    private void setShouShi()
    {

    }
    /**
     *
     * 设置左滑收拾
     */
    public void showDrawUtil()
    {
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.drawline_in);

       // TranslateAnimation ta=new TranslateAnimation(-200,0,0,0);

       // ll_drawline.startAnimation(ta);
      // List<DBStyle> list= DBManager.getInstance().getStyle();

        ll_style.show();
        kLineView.setStyleBack(new MsgView.IcbCall() {
            @Override
            public void call(Object obj, float x, float y) {
                if(obj instanceof  Integer)
                {
                    ll_style.setSelect((Integer) obj);
                }


                if(obj instanceof Bitmap) {
                    int height = DensityUtil.dp2px(80);
                    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(height,height);
                    int width = DisplayUtil.getScreenHeight(context);
                    if (x < width / 2) {
                        lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);


                    } else {
                        lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                    }
                    int m = DensityUtil.dp2px(16);
                    lp.setMargins(m, m, m, m);


                    iv_fangdajin.setImageBitmap((Bitmap) obj);
                    iv_fangdajin.setLayoutParams(lp);
                    iv_fangdajin.setVisibility(VISIBLE);
                }
            }

            @Override
            public void cancle(Object obj) {
                  iv_fangdajin.setVisibility(GONE);
            }
        });
    }

    public void reSet()
    {

    }


}
